<?php
namespace app\admin\controller;

use app\common\controller\AdminBaseController;
use app\admin\model\System as SystemModel;
use think\Cache;
use think\Db;

/**
 * 联系我们
 * Class System
 * @package app\admin\controller
 */
class LxweController extends AdminBaseController {
	
	protected $system_model;

	protected function _initialize() {
		parent::_initialize();
		$this->system_model = new SystemModel();
	}

    /**
     * 站点配置
     */
    public function index() {
         if ($this->request->isPost()) {
            $lxwe_config   = $this->request->post('lxwe_config/a');
            $data['value'] = serialize($lxwe_config);
			$data['name'] = "lxwe_config";
            if (Db::name('system')->where('name', 'lxwe_config')->update($data) !== false) {
                Cache::set('lxwe_config', $lxwe_config);
                $this->success('提交成功');
            } else {
                $this->error('提交失败');
            }
        }else{
        	if (Cache::has('lxwe_config')) {
	            $lxwe_config = Cache::get('lxwe_config');
	        } else {
	            $lxwe_config = Db::name('system')->field('value')->where('name', 'lxwe_config')->find();
	            $lxwe_config = unserialize($lxwe_config['value']);
	        }
	        return $this->fetch('index', ['lxwe_config' => $lxwe_config]);
        }
    }
}